<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
        <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>       
        <link href="assets/css/codemirror.css" rel="stylesheet">
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
        <link rel="stylesheet" href="font/css/font-awesome.min.css" />
        	<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="js/jquery-1.9.1.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
		<script src="assets/js/typeahead-bs2.min.js"></script>
        <script src="assets/layer/layer.js" type="text/javascript" ></script>
        <script src="assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="assets/js/jquery.ui.touch-punch.min.js"></script>
        <script src="assets/js/ace-elements.min.js"></script>
		<script src="assets/js/ace.min.js"></script>

<title>系统设置</title>

</head>

<body>
<div class="margin clearfix">
 <div class="stystems_style">
  <div class="tabbable">
	<ul class="nav nav-tabs" id="myTab">
<!--	  <li class="active">-->
<!--		<a data-toggle="tab" href="#home"><i class="green fa fa-home bigger-110"></i>&nbsp;基本设置</a></li>-->
<!--      <li class="">-->
<!--		<a data-toggle="tab" href="#profile">消息通知<span class="badge badge-danger">4</span></a></li>-->
<!--      <li class="">-->
<!--		<a data-toggle="tab" data-toggle="dropdown" class="dropdown-toggle" href="#dropdown">底部菜单</a>-->
<!--      </li>-->
<!--        <li class="">-->
<!--		<a data-toggle="tab" data-toggle="dropdown" class="dropdown-toggle" href="#other">屏蔽字设置</a>-->
<!--      </li>-->
	</ul>
    <div class="tab-content">
<!--		<div id="home" class="tab-pane active">-->
<!--         <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>网站名称： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="控制在25个字、50个字节以内" value="" class="col-xs-10 "></div>-->
<!--          </div>-->
<!--           <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>网站icon图标： </label>-->
<!--          <div class="col-sm-9"><input type="file" id="id-input-file-2"  /></div>-->
<!--          </div>-->
<!--          <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>关键词： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="5个左右,8汉字以内,用英文,隔开" value="" class="col-xs-10 "></div>-->
<!--          </div>-->
<!--	      <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>文件路径配置： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="默认为空，为相对路径" value="" class="col-xs-10"></div>-->
<!--          </div>-->
<!--          <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>描述： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="空制在80个汉字，160个字符以内" value="" class="col-xs-10"></div>-->
<!--          </div>-->
<!--          <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>底部版权信息： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="" value="" class="col-xs-10 "></div>-->
<!--          </div>-->
<!--          <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>备案号： </label>-->
<!--          <div class="col-sm-9"><input type="text" id="website-title" placeholder="" value="" class="col-xs-10 "></div>-->
<!--          </div>-->
<!--           <div class="form-group"><label class="col-sm-1 control-label no-padding-right" for="form-field-1"><i>*</i>统计代码： </label>-->
<!--          <div class="col-sm-9"><textarea class="textarea"></textarea></div>-->
<!--          </div>-->
<!--          <div class="Button_operation"> -->
<!--				<button onclick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="fa fa-save "></i>&nbsp;保存</button>-->
<!--				-->
<!--				<button onclick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>-->
<!--               -->
<!--			</div>-->
<!--        </div>-->
<!--        <div id="profile" class="tab-pane ">-->
<!--        -->
<!--        </div>-->
<!--        <div id="dropdown" class="tab-pane">-->
<!--          -->
<!--		</div>-->
		<div id="other" class="tab-pane active">
            <div class="search_style">

                <ul class="search_content clearfix">
                    <li><label class="l_f">关键字</label><input name="" type="text"  id="text" class="text_add" placeholder=""  style=" width:400px"/></li>
                    <li style="width:90px;"><button type="button" class="btn_search" onclick="searchKeyword()"><i class="fa fa-search"></i>查询</button></li>
                    <li style="width:90px;"><button type="button" class="btn_search" onclick="queryAll()"><i class="fa fa-search"></i>所有</button></li>
                </ul>
            </div>
            <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:void(0)" id="administrator_add" class="btn btn-warning"><i class="fa fa-plus"></i> 添加关键字</a>
           <!--        <a href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>-->
       </span>
                <span class="r_f">共：<b id="sum"></b>条</span>
            </div>
            <div class="table_menu_list"  id="testIframe">
                <table class="table table-striped table-bordered table-hover" id="sample_table">
                    <thead id="sample-table-tbody">
                    <tr>
                        <th width="80px">编号</th>
                        <th width="250px">屏蔽字</th>
                        <th width="70px">状态</th>
                        <th width="70px">操作</th>
                    </tr>
                    </thead>
                    <tbody id="keywordsTbody">
                    </tbody>
                </table>
            </div>
            <div id="pageBox" style="margin-top: 5%">
                <button id="upPage" onclick="up()" style="margin-left: 42%">上一页</button>
                <input type="text" id="page" style="width: 35px;text-align: center"/>&emsp;/<input type="text" id="total" style="width: 35px;text-align: center" disabled="disabled"/>
                <button id="nextPage" onclick="next()">下一页</button>
            </div>
		 <!--  <div class="form-group"><label class="col-sm-1 control-label no-padding-right"><i>*</i>屏蔽词： </label>
          <div class="col-sm-9"><textarea class="textarea" id="keyword"></textarea></div>
          </div>
          <div class="Button_operation">
				<button onclick="article_save_submit();" class="btn btn-primary radius" type="submit"><i class="fa fa-save "></i>&nbsp;保存</button>

				<button onclick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>

			</div>-->
	    </div>
		</div>
		</div>
 </div>
    <!--添加关键字-->
    <div id="add_administrator_style" class="add_menber" style="display:none">
        <form action="" method="post" id="form-admin-add">
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>关键字：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="keyword" name="keyword"  datatype="*2-16">
                </div>
                <div class="col-4"> <span id="span1" class="Validform_checktip"></span></div>
            </div>
            <div id="btnBox">
                <input class="btn btn-primary radius"  onclick="article_save_submit()" type="submit" id="Add_Administrator" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script>
    var pageTotal;  //总页码
    var currentPage = 1;  //当前页码
    var upPage;     //上一页
    var nextPage;    //下一页
    //显示数据库关键字
    queryAll();
    //信息显示
    function info(object) {
        btnDisabled(object);
        var datas = object.datas;
        $("#page").val(object.currentPage);
        pageTotal = object.totalPage;
        $("#total").val(pageTotal);
        $("#sum").text(object.count);
        nextPage = object.nextPage;
        upPage = object.upPage;
        var stopText = "";		//文字
        var stopClass = "";		//类名
        var stopClick = "";     //点击方法
        var stopTitle = "";		//a标签title
        var aStopClass = "";   //a标签class
        var iClass = "";       //i标签class

        var tbody = document.getElementById("keywordsTbody").childNodes;
        if (tbody != null){
            $("#keywordsTbody").empty();
        }
        for(i of datas){
            if (i.keywordState == '1'){
                stopText = "已启用";
                stopClass = 'label label-success radius';
                stopClick = "member_stop(this,"+i.keyId+")";
                stopTitle = "停用";
                aStopClass = 'btn btn-xs btn-success';
                iClass = 'fa fa-check  bigger-120';
            }else {
                stopText = "已停用";
                stopClass = 'label label-defaunt radius';
                stopClick = "member_start(this,"+i.keyId+")";
                stopTitle = "启用";
                aStopClass = 'btn btn-xs';
                iClass = 'fa fa-close bigger-120';
            }
            var tr = document.createElement("tr");
            tr.innerHTML = "<td>"+ i.keyId + "</td>"+
                "<td>"+ i.keyword + "</td>" +
                "<td class=\"td-status\"><span class=\""+ stopClass +"\">"+ stopText +"</span></td>" +
                "<td class=\"td-manage\">" +
                "<a onClick="+ stopClick +"  href=\"javascript:;\" title="+ stopTitle +"  class=\""+ aStopClass +"\"><i class=\""+ iClass +"\"></i></a> " +
                "</td>"
            $("#keywordsTbody").append(tr);
        }
    }

    //判断按钮是否禁用
    function btnDisabled(object) {
        var currentPage = object.currentPage;
        var upPage = object.upPage;
        var nextPage = object.nextPage;
        var upElement = $("#upPage");
        var nextElement = $("#nextPage");
        if (currentPage == upPage){
            upElement.attr("disabled",true);
        }else {
            upElement.attr("disabled",false);
        }
        if (currentPage == nextPage){
            nextElement.attr("disabled",true);
        }else {
            nextElement.attr("disabled",false);
        }
    }

    //上一页
    function up() {
        var text = $("#text").val();
        var upPage = parseInt($("#page").val()) - 1;
        if (text != ""){
            searchText(upPage,text);
        }else {
            var url = "http://localhost:8080/SnacksShop/supManager.do?type=getKeyWord";
            search(url,upPage);
        }

    }
    //下一页
    function next() {
        var text = $("#text").val();
        var nextPage = parseInt($("#page").val()) + 1;
        if (text != ""){
            searchText(nextPage,text);
        }else {
            var url = "http://localhost:8080/SnacksShop/supManager.do?type=getKeyWord";
            search(url,nextPage)
        }

    }
    var pageText = $("#page");
    //数字框的回车
    document.getElementById("page").addEventListener("keyup",function (event) {
        event.preventDefault();
        if (event.keyCode === 13){
            var values = pageText.val();
            if (isNaN(values)){
                layer.alert("不是数字 \r\n",{
                    title: '提示框',
                    icon:0,
                });
                $("#page").val(currentPage);
            }else {
                if (values > pageTotal){
                    $("#page").val(currentPage);
                    layer.alert("没有了 \r\n",{
                        title: '提示框',
                        icon:0,
                    });
                }else {
                    var currentPageTemp = $("#page").val();
                    var url = "http://localhost:8080/SnacksShop/supManager.do?type=getKeyWord";
                    search(url,currentPageTemp);
                }
            }
        }
    });
    //页码查询
    function search(url,page) {
        $.ajax({
            url: url,
            data:{
                currentPage:page,
                pageSize:10
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.keywords.message == '200') {
                    var object = obj.keywords.object;
                    info(object);
                }
            },
            error:function (data){

            }
        });
    }

    $('#id-input-file-2').ace_file_input({
					no_file:'选择上传图标 ...',
					btn_choose:'选择',
					btn_change:'更改',
					droppable:false,
					onchange:null,
					thumbnail:false, //| true | large
					whitelist:'gif|png|jpg|jpeg'
					//blacklist:'exe|php'
					//onchange:''
					//
				});
    //启用和禁用
    function userStatus(urlStatus,id,msg) {
        $.ajax({
            url: "http://localhost:8080/SnacksShop/supManager.do?type="+urlStatus+"Keyword",
            type: "post",
            data:{
                id:id,
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                msg;
            },
            error:function (data){

            }
        });
    }
    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,'+id+')" href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
            $(obj).remove();
            userStatus('stop',id,layer.msg('已停用!',{icon: 5,time:1000}));
            // layer.msg('已停用!',{icon: 5,time:1000});
        });
    }
    /*用户-启用*/
    function member_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,'+id+')" href="javascript:;" title="停用"><i class="fa fa-check  bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
            $(obj).remove();
            userStatus('start',id,layer.msg('已启用!',{icon: 6,time:1000}));
            // layer.msg('已启用!',{icon: 6,time:1000});
        });
    }

    /*添加关键字*/
    $('#administrator_add').on('click', function(){
        layer.open({
            type: 1,
            title:'添加管理员',
            area: ['700px',''],
            shadeClose: false,
            content: $('#add_administrator_style'),
        });
        // $("#Add_Administrator").attr("onclick","put()");
    });
    //验证关键字是否存在
    document.getElementById("Add_Administrator").addEventListener("mouseover",function (){
        var keyword = $("#keyword").val();
        if (keyword == ""){
            layer.alert("关键字不能为空 \r\n",{
                title: '提示框',
                icon:0,
            });
        }else {
            $.ajax({
                url: "http://localhost:8080/SnacksShop/supManager.do?type=verifyKeyword",
                type: "post",
                data:{
                    keyword:keyword,
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success:function (data){
                    var obj = JSON.parse(data);
                    if (obj.status == '200'){
                        layer.alert("关键字已存在 \r\n",{
                            title: '提示框',
                            icon:0,
                        });
                        $("#Add_Administrator").attr("disabled",true);
                    }
                },
                error:function (data){

                }
            });
        }
    });

    document.getElementById("btnBox").addEventListener("mouseout",function (){
        $("#Add_Administrator").attr("disabled",false);
    });
    //关键字保存
    function article_save_submit() {
        var keyword = $("#keyword").val();
            $.ajax({
                url: "http://localhost:8080/SnacksShop/supManager.do?type=addKeyword",
                type: "post",
                data:{
                    keyword:keyword,
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                type: "post",
                success:function (data){
                    var obj = JSON.parse(data);
                    if (obj.status = '200'){
                        layer.alert("添加成功 \r\n",{
                            title: '提示框',
                            icon:0,
                        });
                    }else {
                        layer.alert("添加失败 \r\n",{
                            title: '提示框',
                            icon:0,
                        });
                    }
                },
                error:function (data){

                }
            });
    }

    //查询
    function searchKeyword() {
        var text = $("#text").val();
        if (text == ""){
            layer.alert("条件为空 \r\n",{
                title: '提示框',
                icon:0,
            });
        }else {
            searchText(1,text);
            // $.ajax({
            //     url: "http://localhost:8080/SnacksShop/supManager.do?type=queryKeyword",
            //     type: "post",
            //     data:{
            //         searchText:text,
            //         currentPage:1,
            //         pageSize:10
            //     },
            //     crossDomain: true,
            //     xhrFields: {
            //         withCredentials: true
            //     },
            //     type: "post",
            //     success:function (data){
            //         var obj = JSON.parse(data);
            //         if (obj.keywords.message == '200'){
            //             info(obj.keywords.object);
            //         }else {
            //             layer.alert("没有您想要的结果 \r\n",{
            //                 title: '提示框',
            //                 icon:0,
            //             });
            //         }
            //     },
            //     error:function (data){
            //
            //     }
            // });
        }
    }

    //查询（上一页。下一页）
    function searchText(currentPage,text) {
        $.ajax({
            url: "http://localhost:8080/SnacksShop/supManager.do?type=queryKeyword",
            type: "post",
            data:{
                searchText:text,
                currentPage:currentPage,
                pageSize:10
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                console.log(obj);
                if (obj.keywords.message == '200'){
                    info(obj.keywords.object);
                }else {
                    layer.alert("没有您想要的结果 \r\n",{
                        title: '提示框',
                        icon:0,
                    });
                    $("#text").val("");
                }
            },
            error:function (data){

            }
        });
    }

    function queryAll() {
        $("#text").val("");
        $.ajax({
            url: "http://localhost:8080/SnacksShop/supManager.do?type=getKeyWord",
            type: "post",
            data:{
                currentPage:currentPage,
                pageSize:10
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            type: "post",
            success:function (data){
                var obj = JSON.parse(data);
                if (obj.keywords.message == '200'){
                    info(obj.keywords.object);
                }
            },
            error:function (data){

            }
        });
    }
</script>
